#include "CoverageTable.h"

using namespace std;

CoverageTable::CoverageTable()
{}

CoverageTable::~CoverageTable()
{}

void CoverageTable::clean()
{
	for(int i=0;i<5000;i++)
		for(int j=0;j<200;j++)
			table[i][j]=0;
}

bool CoverageTable::CheckBit(int row, int col)
{
	if(table[row][col])
		return true;
	else return false;
}

void CoverageTable::SetBit(int row, int col)
{
	table[row][col]=1;
}

double CoverageTable::CalcPercent(vector<int>& pa)
{
	int size=pa.size();
	int covered=0;
	int total=0;
	for(int i=0;i<size-1;i++)
	{
		for(int j=i+1;j<size;j++)
		{
			int row=size*i-(i*(i+1)>>1)+j-i-1;
			for(int k=0;k<pa[i];k++)
			{
				for(int m=0;m<pa[j];m++)
				{
					total++;
					if(CheckBit(row,k*11+m))
						covered++;
				}
			}
		}
	}
	
	return (double)covered/(double)total;
}